$(function () {
    container.off('click');
    function getEquipmentScrapByNameAndState(page) {
        axios({
            url:url,
            params:{
                "async":true,
                "page":page,
                "state":$("#esState").val(),
                "equipmentName":$("#searchName").val()
            }
        }).then(function (response) {
            $("#mainContainer").html(response.data);
        }).catch(function (error) {
            toastr.error("error!");
        });
    }
    //分页
    $.tbpage("#mainContainer",function (page) {
        getEquipmentScrapByNameAndState(page);
    });

    //搜索
    $("#searchNameBtn").click(function () {
        getEquipmentScrapByNameAndState(0);
    });

    container.on('click','#audit-equipmentScrap',function () {
        // 获取 CSRF Token
        var csrfToken = $("meta[name='_csrf']").attr("content");
        axios({
            url:'audit/equipmentScrap/'+$(this).attr("equipmentScrapId"),
            method:'POST',
            params:{
                "state":+$(this).attr("state")
            },
            headers:{'X-CSRF-TOKEN':csrfToken}
        }).then(function (response) {
            getEquipmentScrapByNameAndState(0);
            if(response.data.success){
                toastr.success(response.data.message);
            }else {
                toastr.error(response.data.message);
            }
        }).catch(function (error) {
            toastr.error("error!");
        });
    });

});